package com.zplus.managers.petservices.services.impls;

import com.zplus.managers.petservices.entities.User;
import com.zplus.managers.petservices.mappers.UserMapper;
import com.zplus.managers.petservices.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService
{
    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean register(User user)
    {
        int i = userMapper.addUser(user);
        return i > 0;
    }

    @Override
    public boolean delUser(User user)
    {
        return userMapper.dropUser(user) > 0;
    }

    @Override
    public List<User> queryAllUser()
    {
        return userMapper.queryAllUser();
    }

    @Override
    public User queryUserById(int id)
    {
        return userMapper.queryUserByid(id);
    }

    @Override
    public List<User> queryUserByName(String name)
    {
        List<User> users = userMapper.queryUserByName(name);
        return users;
    }

    @Override
    public boolean updateUserInfo(User userAft)
    {
        int i = userMapper.updateUserInfo(userAft);
        return i > 0;
    }

    @Override
    public User checkLogin(User user)
    {
        User user1 = userMapper.queryUserByPhone(user.getPhoneNum());
        if(user1 == null)
            return null;
        if (user1.getSecret().equals(user.getSecret()))
            return user1;
        return null;
    }
}
